/*
 Copyright (C) 2008  Maurizio Monticelli

 This program is free software; you can redistribute it and/or modify it under the terms of the 
 GNU General Public License as published by the Free Software Foundation; either version 2 of the 
 License, or (at your option) any later version.

 This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 
 even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 
 Public License for more details.

 You should have received a copy of the GNU General Public License along with this program; if not, write 
 to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 
 */

package ch.justdoit.andriodrpncalc.view;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.View;
import android.widget.AbsoluteLayout;
import ch.justdoit.andriodrpncalc.model.Model;

public class MenuBar extends AbsoluteLayout implements MenuBarItemInterface {

	public Model mModel;
	public int WIDTH = 90;
	public int HEIGHT = 120;
	protected String menuName;
	protected List<AbsoluteLayout> layerList;
	private int layerVisible = 0;

	public MenuBar(Context context, Model _model, MenuGroup menuGroup,
			String _menuName) {
		super(context);
		//setBackgroundColor(0xff2d3b2d);
		mModel = _model;
		menuName = _menuName;
		menuGroup.registerMenu(this);
		layerList = new ArrayList<AbsoluteLayout>();
	}

	@Override
	public boolean isVisble() {
		boolean result = false;
		if (this.getVisibility() == View.VISIBLE) {
			result = true;
		}
		return result;
	}

	@Override
	public void setInvisible() {
		this.setVisibility(INVISIBLE);
	}

	@Override
	public void setVisible() {
		this.setVisibility(VISIBLE);
	}

	public String getMenuName() {
		return menuName;
	}

	@Override
	public void nextMenu() {
		// set next Layer visible

		if (!layerList.isEmpty()) {
			for (int i = 0; i < layerList.size(); i++) {
				if (layerList.get(i).getVisibility() == VISIBLE) {

					layerList.get(i).setVisibility(INVISIBLE);
					layerVisible = i;

				}
			}

			if (layerVisible == layerList.size() - 1) {
				layerVisible = 0;
			} else {
				layerVisible++;
			}

			layerList.get(layerVisible).setVisibility(VISIBLE);
		}

	}
}